// pages/device/device.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showDeviceDetail: false, // 控制设备详情弹窗显示
        currentDeviceIndex: -1, // 当前选中的设备索引
        deviceList: [
            {
                deviceId: 'device001',
                deviceName: '吧唧之王',
                macAddress: 'A4:CF:12:3B:9F:88',
                firmwareVersion: 'v1.0.0',
                hardwareVersion: 'C3-Display-RevA',
                productSeries: 'ChiYu Baji -360',
                bindingStatus: '已绑定',
                boundUser: 'abcd1234',
                touchAuth: '已授权',
                authExpireTime: '2025-11-30 12:00:00',
                networkType: 'Wi-Fi',
                wifiSignalStrength: '-58 dBm',
                deviceIp: '192.168.1.102',
                totalStorage: '2048 KB',
                usedStorage: '512 KB',
                storageUsage: '25%',
                storedImages: '10 张',
                maxStorage: '60 张',
                batteryVoltage: '3.92 V',
                batteryLevel: '86%',
                uptime: '1,023,456 ms',
                securityCode: '684321',
                checksum: 'e8f7ab29d4...',
                systemTimestamp: '1,023,456'
            },
            {
                deviceId: 'device002',
                deviceName: '大吧唧',
                macAddress: 'B5:DG:23:4C:0A:99',
                firmwareVersion: 'v1.1.0',
                hardwareVersion: 'C3-Display-RevA',
                productSeries: 'ChiYu Baji -360',
                bindingStatus: '已绑定',
                boundUser: 'efgh5678',
                touchAuth: '已授权',
                authExpireTime: '2025-12-31 12:00:00',
                networkType: 'Wi-Fi',
                wifiSignalStrength: '-62 dBm',
                deviceIp: '192.168.1.103',
                totalStorage: '2048 KB',
                usedStorage: '1024 KB',
                storageUsage: '50%',
                storedImages: '25 张',
                maxStorage: '60 张',
                batteryVoltage: '3.85 V',
                batteryLevel: '75%',
                uptime: '2,045,678 ms',
                securityCode: '785432',
                checksum: 'f9g8bc39e5...',
                systemTimestamp: '2,045,678'
            }
        ],
        deviceInfo: {
            deviceId: '',
            deviceName: '',
            macAddress: '',
            firmwareVersion: '',
            hardwareVersion: '',
            productSeries: '',
            bindingStatus: '',
            boundUser: '',
            touchAuth: '',
            authExpireTime: '',
            networkType: '',
            wifiSignalStrength: '',
            deviceIp: '',
            totalStorage: '',
            usedStorage: '',
            storageUsage: '',
            storedImages: '',
            maxStorage: '',
            batteryVoltage: '',
            batteryLevel: '',
            uptime: '',
            securityCode: '',
            checksum: '',
            systemTimestamp: ''
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },

    /**
     * 返回按钮点击事件
     */
    onBackTap() {
        wx.navigateBack();
    },

    /**
     * 消息按钮点击事件
     */
    onMessageTap() {
        // TODO: 跳转到消息页面
        console.log('点击消息');
    },

    /**
     * 设备卡片点击事件
     */
    onDeviceTap(e) {
        const index = e.currentTarget.dataset.index;
        if (index >= 0 && index < this.data.deviceList.length) {
            const device = this.data.deviceList[index];
            this.setData({
                currentDeviceIndex: index,
                deviceInfo: device,
                showDeviceDetail: true
            });
        }
    },

    /**
     * 阻止事件冒泡
     */
    stopPropagation() {
        // 阻止事件冒泡，防止点击弹窗内部时关闭弹窗
    },

    /**
     * 关闭设备详情弹窗
     */
    closeDeviceDetail() {
        this.setData({
            showDeviceDetail: false,
            currentDeviceIndex: -1
        });
    },

    /**
     * 设备详情弹窗内的返回按钮
     */
    onDetailBackTap() {
        this.closeDeviceDetail();
    },

    /**
     * 设备详情弹窗内的消息按钮
     */
    onDetailMessageTap() {
        // TODO: 跳转到消息页面
        console.log('点击消息');
    },

    /**
     * 添加设备按钮点击事件
     */
    onAddDeviceTap() {
        wx.navigateTo({
            url: '/pages/device/add/add'
        });
    }
})
